package kneipe;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import kneipe.kneipenbereiche.Kneipenbereich;
import kneipe.personen.Person;

public class Seat extends JButton {
	private static final long serialVersionUID = 1L;
	private Kneipenbereich<?> area;
	private Person<?> person;
	private int number;

	public Seat() {
		this(null, -1);
	}

	public Seat(Kneipenbereich<?> area, int platzNummer) {
		this.setNumber(platzNummer);
		this.area = area;
		if (!(area == null))
			this.setText(area.getAreaName() + "-" + getNumber());
		this.person = null;
		this.setBackground(Color.GREEN);
		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new GuestPopup(getPerson());
			}
		});
	}

	public Seat(Kneipenbereich<?> area) {
		this.area = area;
	}

	public Kneipenbereich<?> getArea() {
		return this.area;
	}

	public void setArea(Kneipenbereich<?> area) {
		this.area = area;
	}

	public Person<?> getPerson() {
		return person;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public void reserveFor(Person<?> person) {
		this.person = person;
		this.setBackground(Color.RED);
	}

	public void free(Person<?> guest) {
		this.setBackground(Color.GREEN);
		this.person = null;
	}

	@Override
	public String toString() {
		return "Platz Nr. " + this.number + " (" + this.area.getAreaName()
				+ ")";
	}

}
